package com.javawork.juc.four;

import java.util.concurrent.TimeUnit;

/**
 * @author zhangxiaolu
 * @since 2023-02-11 17:25
 */
public class VolatileSeeDemo {

    static volatile boolean flag = true;
    public static void main(String[] args) {
        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "--------come in");
            while (flag) {

            }
            System.out.println(Thread.currentThread().getName() + "-----flag 更新为false，程序停止");
        }, "t1").start();

        try {
            TimeUnit.MILLISECONDS.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        flag = false;
        System.out.println(Thread.currentThread().getName() + "-----flag 修改完成");
    }
}
